package com.sky.controller.admin;

import com.sky.constant.JwtClaimsConstant;
import com.sky.entity.User;
import com.sky.properties.JwtProperties;
import com.sky.result.Result;
import com.sky.service.UserService;
import com.sky.utils.JwtUtil;
import io.jsonwebtoken.Claims;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/user")
@Api(tags = "管理端用户相关接口")
@Slf4j
public class AdminUserController {
    
    @Autowired
    private UserService userService;
    
    @Autowired
    private JwtProperties jwtProperties;
    
    @GetMapping("/infos")    // 修改为与前端请求匹配的路径
    @ApiOperation("获取用户信息")
    public Result<User> info(@RequestHeader String token) {
        log.info("获取用户信息");
        Claims claims = JwtUtil.parseJWT(jwtProperties.getUserSecretKey(), token);
        Long userId = Long.valueOf(claims.get(JwtClaimsConstant.USER_ID).toString());
        User user = userService.getById(userId);
        return Result.success(user);
    }
}